// pages/book/list/index.js
let id
let p = 0
Page({

    /**
     * 页面的初始数据
     */
    data: {
        booklist:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        id = options.id || '62eb748a5ba9a90d4c17eba8'
        let skip = p*12
        getApp().fly.get(`/classes/books?where={"cateid":"${id}"}&limit=12&skip=${skip}`).then(res=>{
            this.setData({
                booklist:res.data.results
            })
            p++
        })
    },
    onReachBottom() {
        console.log('触底了');
        let skip = p*12
        getApp().fly.get(`/classes/books?where={"cateid":"${id}"}&limit=12&skip=${skip}`).then(res=>{
            let {results} = res.data
            if(results.length){
                this.setData({
                    booklist:[
                        ...this.data.booklist, //原数据
                        ...results //新数据
                    ]
                })
                p++
            }else{
                wx.showToast({
                  title: '我是有底线的~',
                  icon:'none'
                })
            }
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})